/*
 * yarf.c
 *
 * Copyright 2011 Pieter Agten
 *
 * This file is part of Yarf.
 *
 * Yarf is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Yarf is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Yarf.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @file   yarf.c
 * @author Pieter Agten (pieter.agten@gmail.com)
 * @date   3 sep 2011
 * @brief  Contains the main entry point of the firmware.
 *
 * This file contains the main function, which is the entry point of 
 * the firmware.
 */

#include "yarf.h"


#include "hardware/io.h"
#include "hardware/usart.h"
#include "hardware/steppers.h"
#include "hardware/clock.h"
#include "input/gcode.h"
#include "movement/planner.h"
#include "movement/block_handler.h"
#include "scheduling/periodic.h"
#include "temperature/temperature.h"

#include <avr/interrupt.h>

/**
 * The fuse values for the MCU.
 *
 * These fuse values will be placed in a special section in the ELF output
 * file, after linking. By embedding the fuse values in the ELF file, the
 * entire firmware is packed into a single file, which can be used to program
 * the entire MCU.
 */
FUSES = 
{
  .low = LFUSE,
  .high = HFUSE,
  .extended = EFUSE,
};



/**
 * The main function, which is the entry point of the firmware.
 *
 * Initializes all components needed to do the actual work and calls the gcode
 * command component in order to start processing incoming gcode commands. The
 * main function does not (and should not) return.
 */
int
main(void)
{
  /* Initialization */
  usart_init();
  io_init();
  clock_init();
  periodic_init();
  temp_init();
  steppers_init();
  gcode_init(&HOST_USART);
  plan_init();
  block_handler_init();

  /* Enable the global interrupt flag */
  sei();

  fprintf(&HOST_USART,"start\n");
  while (true) {
    gcode_process_command();
  }
}

